package cn.huiyunche.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.interfaces.impl.RoleServiceImpl;
import cn.huiyunche.base.service.model.SysAdminRole;
import cn.huiyunche.base.service.vo.Result;

/**
 * main 控制器 
 * @author hdy [Tuffy]
 */
@Controller
@RequestMapping("/role")
public class RoleController {

	@Autowired
	private RoleServiceImpl roleServiceImpl = null;
	
	/**
	 * 角色列表
	 * @return 结果集
	 */
	@RequestMapping(method= RequestMethod.GET)
	@ResponseBody
	public Result<List<SysAdminRole>> allRoles() {
		return this.getRoleServiceImpl().allRole();
	}
	
	/**
	 * 通过主键获取角色信息
	 * @return 结果集
	 */
	@RequestMapping(value = "/{id}", method= RequestMethod.GET)
	@ResponseBody
	public Result<SysAdminRole> byId(@PathVariable Long id) {
		return this.getRoleServiceImpl().byId(id);
	}
	
	/**
	 * 通过主键获取角色信息
	 * @return 结果集
	 */
	@RequestMapping(value = "/edit", method= RequestMethod.POST)
	@ResponseBody
	public Result<String> save(SysAdminRole sar) {
		return this.getRoleServiceImpl().save(sar);
	}
	
	/**
	 * 通过主键获取角色信息
	 * @return 结果集
	 */
	@RequestMapping(value = "/delete", method= RequestMethod.POST)
	@ResponseBody
	public Result<String> remove(Long id) {
		return this.getRoleServiceImpl().remove(id);
	}
	
	private RoleServiceImpl getRoleServiceImpl() {
		return this.roleServiceImpl;
	}
}
